// 云函数入口文件
const cloud = require('wx-server-sdk')
const axios = require('axios')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 蛋卷 新浪 天天基金 同花顺
let sources = ['danjuan', 'sina', 'tiantian', 'tonghuashun']
let apis = {
  danjuan: {
    api: 'https://danjuanapp.com/djapi/fund/estimate-nav/${code}'
  },
  sina: {
    api: 'https://hq.sinajs.cn/?_=&list=fu_${code}'
  },
  tiantian: {
    api: 'http://fundgz.1234567.com.cn/js/${code}.js'
  }
}

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {

  const industysCollecction = db.collection('industrys')
  let { data: industys } = await industysCollecction.get()

  industys = [industys[0]]

  let res
  console.log(industys)
  for (let industy of industys) {
    let { type, code } = industy
    res = await axios({
      url: 'http://www.fund123.cn/matiaria?fundCode=005621',
      method: 'get'
    })
    console.log(res)
  }

  return {
    res: res.data,
    cookies: res.cookies
    
  }
}